#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+100, mod=1e9+7;
int T,n;
ll a[N],s[N];
ll qmi(ll a,ll p) {
    ll res = 1, k = a%mod;
    while(p) {
        if(p&1) {
            res *= k;
            res %= mod;
        }
        p = (p>>1);
        k = k * k;
        k %= mod;
    }
    return res;
}
int main() {
    cin >> T;
    while (T--)
    {
        cin >> n;
        for(int i=1;i<=n;i++) cin >> a[i];
        for(int i=1;i<=n;i++) {
            s[i] = s[i-1] + a[i];
            s[i] %= mod;
        }
        ll P = 0, Q = 0;
        for(int i=1;i<n;i++) {
            P += a[i] * (s[n]-s[i]+mod)%mod;
            P %= mod;
        }
        Q = n*(n-1)/2;
        ll nQ = qmi(Q,mod-2);
        cout << (P * nQ)%mod << endl;
    }
    
    return 0;
}